/***
 * response
 * 发送 json 数据
 */
export class Message<T> {
	constructor(
		public msg: string,
		public code: 200 | 400 | 401 | 402 | 403 | 404 | 500 | 501 | 502 | 503,
		public data: T
	) {}

	static success<T>(data: T) {
		const message = new Message("OK", 200, data);

		return message;
	}

	static err<T>(
		msg: string,
		code: Message<unknown>["code"] = 400,
		data: T = undefined
	) {
		const message = new Message(msg, code, data);
		return message;
	}

	static err404<T>(data: T = undefined) {
		const message = new Message("NOT_FOUND", 404, data);
		return message;
	}

	static noResult<T>(data: T = undefined) {
		const message = new Message("NO_RESULT", 200, data);
		return message;
	}
}
